/*
 * Tangram
 * Copyright 2009 Baidu Inc. All rights reserved.
 *
 * path: ui/dialog/Slider$follow.js
 * author: linlingyu
 * version: 1.0.0
 * date: 2010-12-6
 */
///import baidu.ui.slider.Slider;
///import baidu.ui.progressBar.ProgressBar;
///import baidu.dom.insertHTML;
///import baidu.string.format;
///import baidu.dom.getStyle;
///import baidu.dom.setStyle;
///import baidu.lang.Class.addEventListeners;
/**
 * addon
 *
 * 和进度条结合
 * 进度条跟随滑块的滑动
 */
baidu.ui.slider.Slider.register(function(me){
	me.addEventListener("load", function(){
		baidu.dom.insertHTML(me.getThumb(), "beforeBegin", me.getFollowString());
        me.followProgressBar = new baidu.ui.progressBar.ProgressBar({
            layout : me.layout,
            skin : me.skin ? me.skin + "-followProgressbar" : null
        });
        me.followProgressBar.render(me.getId("followProgressbar"));
        me.follow();
	});
	me.addEventListeners("slide, slideclick", function(){
		me.follow();
	});
});

baidu.ui.slider.Slider.extend({
	tplFollow : "<div id='#{rsid}' class='#{class}' style='position:absolute; left:0px; top:0px;'></div>",
	/**
     * 生成字符串
     */
	getFollowString : function(){
		var me = this;
		return baidu.string.format(me.tplFollow, {
			rsid : me.getId("followProgressbar"),
            "class" : me.getClass("followProgressbar")
		});
	},
    /**
     * 使进度条跟随滑块
     */
	follow : function(){
		var me = this;
		baidu.dom.setStyle(me.followProgressBar.getBar(),
            me.followProgressBar.axis[me.layout].size,
            parseInt(baidu.dom.getStyle(me.getThumb(), me.axis[me.layout].thumbPos)) + me[me.axis[me.layout]._getThumbSize]() / 2 + "px");
		//me.followProgressBar.update({value : me.getValue()});//这里使用update运算不准确
	}
});

